﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;

namespace Mines.Ajax
{
    class AjaxNoneSessionHandler:IHttpHandler
    {
        private AjaxMethod m;
        private Type type;
        private object[] ptypes;
        public AjaxNoneSessionHandler(Type type, AjaxMethod m, object[] _params)
        {
            this.type = type;
            this.m = m;
            this.ptypes = _params;
        }

     public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            var instance = m.methodInfo.IsStatic ? null : Activator.CreateInstance(type);
            var res = m.methodInfo.Execute(instance, ptypes.ToArray());
            context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(new { value = res }));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
